# Main component CMakeLists.txt

set(EPD_DRIVER_SRCS
    ../epd_driver/epd_class.c
    ../epd_driver/gfx/epd_gfx.c
    ../epd_driver/hal/epd_hal.c
    ../epd_driver/driver/epd_ssd167x.c
    ../epd_driver/ports/dev_config_idf.c
)

# 可选地包含生成的苹方字库源文件（如果存在）
set(PINGFANG_SRC "")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ePaper/lib/Fonts/pingfang24cn.c")
    list(APPEND PINGFANG_SRC "ePaper/lib/Fonts/pingfang24cn.c")
endif()

idf_component_register(
    SRCS
        "calendar.c" "ble_module.c"
        ${EPD_DRIVER_SRCS}
        "ePaper/lib/e-Paper/EPD_7in5bc.c"
        "ePaper/lib/GUI/GUI_Paint.c"
        "ePaper/lib/Fonts/font12CN.c"
        "ePaper/lib/Fonts/font24CN.c"
        ${PINGFANG_SRC}
    INCLUDE_DIRS
        "." "../epd_driver" "../epd_driver/hal" "../epd_driver/driver" "../epd_driver/gfx" "../epd_driver/ports"
        "ePaper/lib/Config" "ePaper/lib/e-Paper" "ePaper/lib/GUI" "ePaper/lib/Fonts"
    PRIV_REQUIRES "driver" "esp_driver_gpio" "esp_driver_spi" "nvs_flash" "bt"
)

# 启用蓝牙调试日志
if(CONFIG_BT_ENABLED)
    target_compile_definitions(${COMPONENT_LIB} PRIVATE 
        CONFIG_BT_DEBUG_LOG=1
        CONFIG_BT_GATT_DEBUG_LOG=1
    )
endif()

# 切换至厂商驱动验证：启用EPD并允许通过编译参数覆盖GPIO映射
# 可在构建时添加例如：-DEPD_CS_GPIO=15 -DEPD_DC_GPIO=2 等以匹配实际接线
# 这里提供默认引脚
target_compile_definitions(${COMPONENT_LIB} PRIVATE 
    EPD_ENABLE=1
    EPD_CS_GPIO=5
    EPD_DC_GPIO=17
    EPD_RST_GPIO=16
    EPD_BUSY_GPIO=4
    EPD_SCLK_GPIO=18
    EPD_MOSI_GPIO=23
)

# 兼容第三方GUI_Paint源码的警告（type-limits）
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=type-limits)
# 兼容第三方中文字体表的字符串初始化警告
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=unterminated-string-initialization)
# 暂时关闭将所有警告视为错误（第三方库集成阶段）
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error -Wno-error=unused-function)